package com.ctsi.offlinesupport.service;

import com.ctsi.offlinesupport.constant.SupportFlowConstant;
import com.ctsi.organise.common.api.OrganiseServiceProxy;
import com.ctsi.organise.common.api.PersonServiceProxy;
import org.flowable.engine.delegate.TaskListener;
import org.flowable.task.service.delegate.DelegateTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author: zhangjw
 * @Date: 2018/10/22 09:46
 * @Description: （省，地市）政支主任环节设置参与者
 */
@Component("leaderLinkListener")
public class LeaderLinkListener implements TaskListener {



    @Autowired
    private PersonServiceProxy userServiceProxy;
    @Autowired
    private OrganiseServiceProxy organiseServiceProxy;
    @Autowired
    private SupportUtilService supportUtilService;

    @Override
    public void notify(DelegateTask delegateTask) {
        // 将自动派单置为0
        delegateTask.setVariable(SupportFlowConstant.Variables.ISAUTO.name,0);
        /**
         * 获取流程创建人
         */
//        //String applyUserId = (String) delegateTask.getVariable(SupportFlowConstant.Variables.APPLYUSERID.name);
//        String initator = (String) delegateTask.getVariable("applyUserId");
//        delegateTask.getVariableNames().forEach(str -> System.out.println(str));
//        // 获取流程创建人默认组织（import: 因为政支主任是组织领导）
//        Organise organise = userServiceProxy.getOrganise4User(initator);
//       // String leaderId = this.organiseServiceProxy.getOrganLeaderIds(organise.getPartyId()).get(0);
//        String leaderId = supportUtilService.findSupportMan(organise);
//        // 把政支主任设置为环节处理人
//        //delegateTask.setAssignee(leaderId);
//        Authentication.setAuthenticatedUserId(leaderId);
//        delegateTask.setAssignee(leaderId);
    }

}
